package com.cong.security.core.code.image;

import com.cong.security.core.code.ValidateCode;
import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

public class ImageCode extends ValidateCode {

	private BufferedImage BufferImage;

	/*过期时间*/
	private LocalDateTime expireTime;
	
	/**
	 * 设置在多少秒之后过期
	 * 
	 * @param bufferImage
	 *            图片流
	 * @param code
	 *            验证码
	 * @param expireIn
	 *            秒数
	 */
	public ImageCode(BufferedImage bufferImage, String code, int expireIn) {
		super(code);
		BufferImage = bufferImage;
		// 当前时间+过期时间长度(使用缓存之后此配置即不需要)
		this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
	}

	public BufferedImage getBufferImage() {
		return BufferImage;
	}

	public void setBufferImage(BufferedImage bufferImage) {
		BufferImage = bufferImage;
	}
	
	public boolean isExpried() {
		return LocalDateTime.now().isAfter(expireTime);
	}
}
